package com.xhy.util;

import com.xhy.entity.Category;
import com.xhy.entity.User;
import com.xhy.entity.Video;
import com.xhy.feign.CategoryClients;
import com.xhy.feign.UserClients;
import com.xhy.vo.VideoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class VideoUtils {
    @Autowired
    private UserClients userClients;
    @Autowired
    private CategoryClients categoryClients;
    public VideoVO VideoToVideovo(Video video){
        //创建VideoVo
        VideoVO videoVO = new VideoVO();
        //复制属性
        BeanUtils.copyProperties(video, videoVO);//复制属性

        //视频服务----->调用用户服务 根据用户id查询用户
        User user = userClients.selectById(video.getUid());//调用用户服务
        videoVO.setUploader(user.getName());//设置用户名

        //视频服务---->调用类别服务  根据类别id查询类别
        Category category = categoryClients.selectById(video.getCategoryId());
        videoVO.setCategory(category.getName());

        //设置点赞数量
        videoVO.setLikes(0);

        return videoVO;
    }
}
